package top.hours48.ddbearapi.model;

import lombok.Data;
import top.hours48.ddbearapi.model.exception.BusinessCode;
import top.hours48.ddbearapi.model.exception.BusinessException;

@Data
public class RespVO {
    private Integer code;
    private String msg;

    private Object data;

    public RespVO(Object data) {
        this.code = BusinessCode.SUCCESS.getCode();
        this.msg = BusinessCode.SUCCESS.getMsg();
        this.data = data;
    }


    public RespVO(BusinessCode businessCode) {
        this.code = businessCode.getCode();
        this.msg = businessCode.getMsg();
        this.data = null;
    }

    public RespVO(BusinessException exception) {
        this.code = exception.getCode();
        this.msg = exception.getMsg();
        this.data = null;
    }

    /**
     * 返回实时错误，覆盖枚举错误
     * @param businessCode
     * @param errMessage
     */
    public RespVO(BusinessCode businessCode, String errMessage) {
        this.code = businessCode.getCode();
        this.msg = errMessage;
        this.data = null;
    }

}
